<template>
  <div class="user" style="padding: 0px;">
    <el-card>
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="订单号">
          <el-input v-model="formInline.orderNo" clearable @keyup.enter.native="onSubmit" placeholder="请输入订单号"></el-input>
        </el-form-item>
        <el-form-item label="售后类型">
          <el-select clearable style="width: 150px;" v-model="formInline.type" placeholder="请选择" filterable @change="onSubmit">
            <el-option label="全部" value="0"></el-option>
            <el-option label="退货退款" value="10"></el-option>
            <el-option label="换货" value="20"></el-option>
            <el-option label="退款" value="30"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="起始时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker v-model="formInline.createTime" type="daterange" value-format="YYYY-MM-DD" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="onSubmit">查询</el-button>
          <el-button @click="onReset" icon="Refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    
    <!--内容-->
    <el-card style="margin-top:5px;">
      <el-tabs v-model="activeName" @tab-change="handleClick">
        <el-tab-pane :label="'进行中(' + arr[0] + ')'" name="0"></el-tab-pane>
        <el-tab-pane :label="'已拒绝(' + arr[1] + ')'" name="10"></el-tab-pane>
        <el-tab-pane :label="'已完成(' + arr[2] + ')'" name="20"></el-tab-pane>
        <el-tab-pane :label="'已取消(' + arr[3] + ')'" name="30"></el-tab-pane>
      </el-tabs>
      <el-table :data="tableData" border style="width: 100%" v-loading="loading" stripe>
        <el-table-column type="expand">
          <template #default="props">
            <div style="width: 90%;margin:5px 15px">
              <el-table :data="props.row.orderProductList" :border="true">
                <el-table-column prop="productName" label="商品名称"></el-table-column>
                <el-table-column prop="productAttr" label="规格属性"></el-table-column>
                <el-table-column prop="totalNum" label="购买数量"></el-table-column>
                <el-table-column prop="expectDeliveryTime" label="预计发货日期"></el-table-column>
                <el-table-column prop="productAddress" label="生产部门"></el-table-column>
              </el-table>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="orderNo" label="订单号" width="200"></el-table-column>
        <el-table-column prop="orderCreateTime" label="订单创建时间" width="200"></el-table-column>
        <el-table-column prop="typeText" width="150" label="售后类型">
          <template #default="scope">
            <span class="orange">{{ scope.row.typeText }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="statusText" label="处理状态" width="130">
          <template #default="scope">
            <el-tag class="orange">{{ scope.row.statusText }}</el-tag>
          </template>
        </el-table-column> -->
        <el-table-column prop="applyDesc" label="申请原因" width="200"></el-table-column>
        <el-table-column prop="createTime" label="申请售后时间"></el-table-column>
        <el-table-column prop="user.nickName" label="申请人"></el-table-column>
        <el-table-column prop="" label="处理状态" width="180">
          <template #default="scope">
            <div v-if="scope.row.status == 0">
              <!-- 审核状态-->
              <p>
                商家审核：
                <span class="orange" v-if="scope.row.isAgree == 0">{{
                  scope.row.isAgreeText
                  }}</span>
                <span class="orange" v-if="scope.row.isAgree == 10">{{
                  scope.row.isAgreeText
                  }}</span>
                <span class="orange" v-if="scope.row.isAgree == 20">{{
                  scope.row.isAgreeText
                  }}</span>
              </p>
              <!-- 发货状态-->
              <p v-if="scope.row.type != 30 && scope.row.isAgree == 10">
                用户发货：
                <span class="orange" v-if="scope.row.isUserSend == 0">待发货</span>
                <span class="orange" v-else>已发货</span>
              </p>
              <!-- 商家收货状态-->
              <p v-if="
                scope.row.type != 30 &&
                scope.row.isAgree == 10 &&
                scope.row.is_user_send == 1 &&
                scope.row.is_receipt == 0
              ">
                <span>商家收货：</span>
                <span class="orange">待收货</span>
              </p>
            </div>
            <div v-if="scope.row.status == 20">
              <span>{{ scope.row.statusText }}</span>
            </div>
            <div v-if="scope.row.status == 10">
              <span>{{ scope.row.statusText }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="300">
          <template #default="scope">

            <el-button @click="Detail(scope.row.orderRefundId)" type="text" size="small" icon="Document">详情</el-button>
            <!-- 只保留一个审核 -->
            <el-button v-if="scope.row.auditBtn" @click="Detail(scope.row.orderRefundId)" type="text" size="small" icon="Edit">审核</el-button>
            <!-- 销售总监 -->
            <!-- <el-button v-if="scope.row.flowStatus === 31 && scope.row.isAgree !== 20"
              @click="Detail(scope.row.orderRefundId)" type="text" size="small"
              v-auth="'/order/refund/xszjaudit'">销售总监审核</el-button>
            <el-button v-if="scope.row.flowStatus === 32 && scope.row.isAgree !== 20"
              @click="Detail(scope.row.orderRefundId)" type="text" v-auth="'/order/refund/jdaudit'"
              size="small">生产基地审核</el-button>

            <el-button v-if="scope.row.flowStatus == 40 && scope.row.isAgree !== 20"
              @click="Detail(scope.row.orderRefundId)" type="text" size="small"
              v-auth="'/order/refund/receipt'">财务审核</el-button> -->
            <el-button v-if="
              scope.row.type != 30 &&
              scope.row.is_agree == 10 &&
              scope.row.is_receipt == 0 &&
              scope.row.is_user_send == 1
            " @click="Detail(scope.row.orderRefundId)" type="text" size="small" icon="Promotion">
              处理
            </el-button>

          </template>
        </el-table-column>
      </el-table>

      <el-pagination style="margin-top:10px;margin-bottom:10px;float:right;" @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="curPage" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalDataNumber"></el-pagination>
    </el-card>
  </div>
</template>

<script>
import OrderApi from "@/api/order.js";
import { defaultPageSize } from '@/utils/table.js'
export default {
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 10,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        orderNo: "",
        style_id: "",
        shop_id: "",
        createTime: "",
      },
      status: "0",
      arr: [],
      activeName: "0",
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      this.curPage = val;
      this.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*切换菜单*/
    handleClick(tab, event) {
      this.curPage = 1;
      this.status = tab;
      this.getTableList();
    },

    /*获取列表*/
    getTableList(params = "") {
      let self = this;
      let Params = {};
      self.arr = [0, 0, 0, 0];
      Params.status = self.status;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      if (params != "") {
        Params.orderNo = params.orderNo;
        //Params.createTime = params.createTime;
        if (
          self.formInline.createTime &&
          self.formInline.createTime.length > 1
        ) {
          Params.startDate = self.formInline.createTime[0];
          Params.endDate = self.formInline.createTime[1];
        } else {
          Params.startDate = "";
          Params.endDate = "";
        }
        Params.type = params.type;
      }
      self.loading = true;
      OrderApi.orderrefund(Params, true)
        .then((res) => {
          self.loading = false;
          self.tableData = res.data.list.records;
          self.totalDataNumber = res.data.list.total;
          // self.exStyle = data.data.ex_style;
          // self.shopList = data.data.shopList;
          self.arr = res.data.status;
        })
        .catch((error) => { });
    },

    /*搜索查询*/
    onSubmit() {
      let self = this;
      let Params = this.formInline;
      self.getTableList(Params);
    },
    onReset(){
      let self = this;
      self.formInline.orderNo = null; 
      self.formInline.type = null;
      self.formInline.createTime = null;
      let Params = this.formInline;
      self.getTableList(Params);
    },
    /*详情*/
    Detail(e) {
      let self = this;
      let orderRefundId = e;
      this.$router.push({
        path: "/order/refund/Detail",
        query: {
          orderRefundId: orderRefundId,
        },
      });
    },
  },
};
</script>
<style></style>
